package co.lostreseditores.colegio.presentation.businessDelegate;

import co.lostreseditores.colegio.modelo.Colegio;
import co.lostreseditores.colegio.modelo.Lugar;
import co.lostreseditores.colegio.modelo.control.ColegioLogic;
import co.lostreseditores.colegio.modelo.control.IColegioLogic;
import co.lostreseditores.colegio.modelo.control.ILugarLogic;
import co.lostreseditores.colegio.modelo.control.LugarLogic;
import co.lostreseditores.colegio.modelo.dto.*;

import java.math.BigDecimal;

import java.util.Date;
import java.util.List;
import java.util.Set;


/**
* Use a Business Delegate to reduce coupling between presentation-tier clients and business services.
* The Business Delegate hides the underlying implementation details of the business service, such as lookup and access details of the EJB architecture.
*
* The Business Delegate acts as a client-side business abstraction; it provides an abstraction for, and thus hides,
* the implementation of the business services. Using a Business Delegate reduces the coupling between presentation-tier clients and
* the system's business services. Depending on the implementation strategy, the Business Delegate may shield clients from possible
* volatility in the implementation of the business service API. Potentially, this reduces the number of changes that must be made to the
* presentation-tier client code when the business service API or its underlying implementation changes.
*
* However, interface methods in the Business Delegate may still require modification if the underlying business service API changes.
* Admittedly, though, it is more likely that changes will be made to the business service rather than to the Business Delegate.
*
* Often, developers are skeptical when a design goal such as abstracting the business layer causes additional upfront work in return
* for future gains. However, using this pattern or its strategies results in only a small amount of additional upfront work and provides
* considerable benefits. The main benefit is hiding the details of the underlying service. For example, the client can become transparent
* to naming and lookup services. The Business Delegate also handles the exceptions from the business services, such as java.rmi.Remote
* exceptions, Java Messages Service (JMS) exceptions and so on. The Business Delegate may intercept such service level exceptions and
* generate application level exceptions instead. Application level exceptions are easier to handle by the clients, and may be user friendly.
* The Business Delegate may also transparently perform any retry or recovery operations necessary in the event of a service failure without
* exposing the client to the problem until it is determined that the problem is not resolvable. These gains present a compelling reason to
* use the pattern.
*
* Another benefit is that the delegate may cache results and references to remote business services. Caching can significantly improve performance,
* because it limits unnecessary and potentially costly round trips over the network.
*
* A Business Delegate uses a component called the Lookup Service. The Lookup Service is responsible for hiding the underlying implementation
* details of the business service lookup code. The Lookup Service may be written as part of the Delegate, but we recommend that it be
* implemented as a separate component, as outlined in the Service Locator pattern (See "Service Locator" on page 368.)
*
* When the Business Delegate is used with a Session Facade, typically there is a one-to-one relationship between the two.
* This one-to-one relationship exists because logic that might have been encapsulated in a Business Delegate relating to its interaction
* with multiple business services (creating a one-to-many relationship) will often be factored back into a Session Facade.
*
* Finally, it should be noted that this pattern could be used to reduce coupling between other tiers, not simply the presentation and the
* business tiers.
*
* @author Zathura Code Generator http://code.google.com/p/zathura
*
*/
public class BusinessDelegatorView {
    private BusinessDelegatorView() {
    }

    public static List<Colegio> getColegio() throws Exception {
        IColegioLogic colegioLogic = new ColegioLogic();

        return colegioLogic.getColegio();
    }

    public static void saveColegio(Long colecoddanen, String coledescripv,
            Integer coleidn, Long lugaidn) throws Exception {
            IColegioLogic colegioLogic = new ColegioLogic();
            colegioLogic.saveColegio(colecoddanen, coledescripv, coleidn, 
                 lugaidn);
        }

    public static void deleteColegio(Integer coleidn) throws Exception {
        IColegioLogic colegioLogic = new ColegioLogic();
        colegioLogic.deleteColegio(coleidn);
    }

    public static void updateColegio(Long colecoddanen, String coledescripv,
        String coledireccionv, String coleemailv, String colefaxv,
        Integer coleidn, String colelogov, String colesectorv,
        String coletelefonofv, String colezonav, Integer comuidn, Long lugaidn)
        throws Exception {
        IColegioLogic colegioLogic = new ColegioLogic();
        colegioLogic.updateColegio(colecoddanen, coledescripv, coledireccionv,
            coleemailv, colefaxv, coleidn, colelogov, colesectorv,
            coletelefonofv, colezonav, comuidn, lugaidn);
    }

    public static Colegio getColegio(Integer coleidn) throws Exception {
        IColegioLogic colegioLogic = new ColegioLogic();
        Colegio colegio = null;

        try {
            colegio = colegioLogic.getColegio(coleidn);
        } catch (Exception e) {
            throw e;
        }

        return colegio;
    }

    public static List<Colegio> findByCriteriaInColegio(Object[] variables,
        Object[] variablesBetween, Object[] variablesBetweenDates)
        throws Exception {
        IColegioLogic colegioLogic = new ColegioLogic();

        return colegioLogic.findByCriteria(variables, variablesBetween,
            variablesBetweenDates);
    }

    public static List<Colegio> findPageColegio(String sortColumnName,
        boolean sortAscending, int startRow, int maxResults)
        throws Exception {
        IColegioLogic colegioLogic = new ColegioLogic();

        return colegioLogic.findPageColegio(sortColumnName, sortAscending,
            startRow, maxResults);
    }

    public static Long findTotalNumberColegio() throws Exception {
        IColegioLogic colegioLogic = new ColegioLogic();

        return colegioLogic.findTotalNumberColegio();
    }

    public static List<ColegioDTO> getDataColegio() throws Exception {
        IColegioLogic colegioLogic = new ColegioLogic();

        return colegioLogic.getDataColegio();
    }
    
    
    public static Colegio getColegioDane(Long coleDane) throws Exception {
        IColegioLogic colegioLogic = new ColegioLogic();
        //Colegio colegio = null;
        List<Colegio> colegios;
        try {
             colegios = colegioLogic.getColegioDane(coleDane);
        } catch (Exception e) {
            throw e;
        }

        return colegios.get(0);
    }
    

    public static List<Lugar> getLugar() throws Exception {
        ILugarLogic lugarLogic = new LugarLogic();

        return lugarLogic.getLugar();
    }

    public static void saveLugar(Long lugacoddanen, String lugadescripv,
        Integer lugaidn, Integer lugaidn_Lugar) throws Exception {
        ILugarLogic lugarLogic = new LugarLogic();
        lugarLogic.saveLugar(lugacoddanen, lugadescripv, lugaidn, lugaidn_Lugar);
    }

    public static void deleteLugar(Integer lugaidn) throws Exception {
        ILugarLogic lugarLogic = new LugarLogic();
        lugarLogic.deleteLugar(lugaidn);
    }

    public static void updateLugar(Long lugacoddanen, String lugadescripv,
        Integer lugaidn, Integer lugaidn_Lugar) throws Exception {
        ILugarLogic lugarLogic = new LugarLogic();
        lugarLogic.updateLugar(lugacoddanen, lugadescripv, lugaidn,
            lugaidn_Lugar);
    }

    public static Lugar getLugar(Integer lugaidn) throws Exception {
        ILugarLogic lugarLogic = new LugarLogic();
        Lugar lugar = null;

        try {
            lugar = lugarLogic.getLugar(lugaidn);
        } catch (Exception e) {
            throw e;
        }

        return lugar;
    }

    public static List<Lugar> findByCriteriaInLugar(Object[] variables,
        Object[] variablesBetween, Object[] variablesBetweenDates)
        throws Exception {
        ILugarLogic lugarLogic = new LugarLogic();

        return lugarLogic.findByCriteria(variables, variablesBetween,
            variablesBetweenDates);
    }

    public static List<Lugar> findPageLugar(String sortColumnName,
        boolean sortAscending, int startRow, int maxResults)
        throws Exception {
        ILugarLogic lugarLogic = new LugarLogic();

        return lugarLogic.findPageLugar(sortColumnName, sortAscending,
            startRow, maxResults);
    }

    public static Long findTotalNumberLugar() throws Exception {
        ILugarLogic lugarLogic = new LugarLogic();

        return lugarLogic.findTotalNumberLugar();
    }

    public static List<LugarDTO> getDataLugar() throws Exception {
        ILugarLogic lugarLogic = new LugarLogic();

        return lugarLogic.getDataLugar();
    }
    
    public static List<Lugar> getCiudades(Integer lugaidn) throws Exception {
        ILugarLogic lugarLogic = new LugarLogic();

        return lugarLogic.getCiudades(lugaidn);
    }
    
    public static Lugar getLugarDane(Long lugaidn) throws Exception {
        ILugarLogic lugarLogic = new LugarLogic();
        Lugar lugar = null;

        try {
            lugar = lugarLogic.getLugarDane(lugaidn);
        } catch (Exception e) {
            throw e;
        }

        return lugar;
    }
    
    public static List<Lugar> getDptos() throws Exception {
        ILugarLogic lugarLogic = new LugarLogic();

        return lugarLogic.getDptos();
    }
}
